package util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class Methods {
	public static BufferedReader BuildBufferedReader(String path){
		File file = new File(path);
		if(!file.exists())
			return null;
		FileReader fileReader=null;
		BufferedReader bufferReader = null;
		try{
			fileReader = new FileReader(file);
			bufferReader = new BufferedReader(fileReader);
			return bufferReader;
		}
		catch(IOException e){
			e.printStackTrace();
			return null;
		}
		finally{
			try {
				fileReader.close();
				bufferReader.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	public static BufferedWriter BuildBufferedWriter(String path){
		File file = new File(path);
		if(!file.exists())
			try {
				file.createNewFile();
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		FileWriter fileWriter=null;
		BufferedWriter bufferWriter = null;
		try{
			fileWriter = new FileWriter(file);
			bufferWriter = new BufferedWriter(fileWriter);
			return bufferWriter;
		}
		catch(IOException e){
			e.printStackTrace();
			return null;
		}
		finally{
			try {
				fileWriter.close();
				//bufferWriter.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	
	public static String getType(String type){
		int low=0;
		for (int i = 0; i < type.length(); i++) {
			if (type.charAt(i) == '[')
				low = i;
		}
		return type.substring(0, low);
	}
}
